import { observable, action, asMap } from 'mobx';

export default class BaseStore{

    @observable variableMap = observable.map ? observable.map({}) : asMap({});

    constructor(){
        this.controlVariableMap = this.controlVariableMap;
        this.batchControlVariableMap = this.batchControlVariableMap;
        // this.changeState = this.changeState.bind(this);
    }

    @action('批量控制变量区')
    batchControlVariableMap = (obj={}) => {
        Object.keys(obj).forEach(key =>{
            this.controlVariableMap(key, obj[key]);
        });
    }

    @action('控制变量区')
    controlVariableMap = (key, value) => {
        this.variableMap.set(key, value);
    }

    @action('重置变量区')
    resetVariableMap(){
        this.variableMap = observable.map ? observable.map({}) : asMap({});
    }

    // @action('自由改变store状态，太暴力，不建议使用，只有改变不常用的状态可以考虑偶尔用用')
    // changeState(params = {}) {
    //     Object.keys(params).forEach(key => {
    //         this[key] = params[key];
    //     });
    //     return this;
    // }
    
}